' ***^^^***|||***^^^***
' 
'  This file is regenerated until it's edited. Delete the file to force regeneration.

'  NOTE: This denotes the way the file was created and it's possible the 
'        generation type has since changed.
'        Check the generation script for the curent state of the file.

' %%%###%%%45e955817f5231d94b269f8e864f5565%%%###%%%
' %%%##NoWS##%%%7b25ec87b869ba8a983e66a03e191b76%%%##NoWS##%%%
' ***^^^***|||***^^^***

  
'************************************************************************************
' Copyright © 2003-2006 Kathleen Dollard
'
' This software is provided 'as-is', without any express or implied warranty. In no 
' event will the author be held liable for any damages arising from the use of this
' software.
' 
' You may use this software for any purpose, including commercial applications, 
' and you may redistribute this software as part of application delivery: however, 
' this copyright notice may not be removed and you may not otherwise redistribute 
' this software directly other than providing a link to wwww.gendotnet.com. 
'
' You may alter this software to better server your needs (I'd like to hear about your 
' changes in order to make the software better). If you alter the softwre, you must  
' clearly mark it as altered and must not be misrepresented as the original software.
' nor wholly your original work.
'*************************************************************************************

Option Explicit On
Option Strict On

Imports System
Imports System.Collections.Generic



Public Class MapChild

End Class

Public Class MapChildCollection
   Public Function Clone() As MapChildCollection
      Dim ret As New MapChildCollection
      For Each child As MapChild In Me
         ret.Add(child)
      Next
      Return ret
   End Function

   Public Function GetUniqueChildName(ByVal child As MapChild) As String
      Dim ret As String = child.Name
      Dim key As String
      If Not IsUnique(child) Then
         For Each childKey As MapRelationKey In child.MapRelationKeys
            key = childKey.ChildProperty
            If key.ToLower.EndsWith("guid") Then
               key = key.Substring(0, key.Length - 4)
            ElseIf key.EndsWith("ID") Or key.EndsWith("Id") Then
               key = key.Substring(0, key.Length - 2)
            End If
            ret &= "_" & key
         Next
      End If
      Return ret
   End Function

   Private Function IsUnique(ByVal child As MapChild) As Boolean
      For Each testChild As MapChild In Me
         If child IsNot testChild Then
            If child.Name = testChild.Name Then
               Return False
            End If
         End If
      Next
      Return True
   End Function

   Public Function GetChildByChildObjectDef(ByVal objectDef As MapObjectDef) As MapChild
      For Each child As MapChild In Me
         If child.MapChildObjectDef Is objectDef Then
            Return child
         End If
      Next
      Return Nothing
   End Function

   Public Function GetChildByName(ByVal name As String) As MapChild
      For Each child As MapChild In Me
         If child.Name = name Then
            Return child
         End If
      Next
      Return Nothing
   End Function

   Public Function GetByTableName(ByVal tableName As String) As MapChild
      For Each child As MapChild In Me
         If String.Equals(child.TableName, tableName, StringComparison.InvariantCultureIgnoreCase) Then
            Return child
         End If
      Next
      Return Nothing
   End Function

End Class

	